import { get, post, postByUrl } from '@/utils/http'
import type { BasicPagingListResult, BasicPagingListParams } from '@/apis/basicModel'
import type {
  GetInspectListParams,
  GetInspectListResult,
  PostCreateCarbonInspectParams,
  PostEditCarbonInspectParams,
  PostSyncInventoryDataResult,
  PostQuotaForecastDataParams,
  PostQuotaForecastDataResult,
  GetFindCarbonAllowanceResult,
  PostCarbonEmissionInspectParams,
  GetOrganizationListResult
} from './model/inspectModel'
enum Api {
  /**
   * 碳核查与履约分页列表
   */
  GET_INSPECT_LIST = '/book/carbonInspect/pageInspect',
  /**
   * 新增工厂核查记录
   */
  CREATE_CARBON_INSPECT = '/book/carbonInspect/createCarbonInspect',
  /**
   * 编辑碳核查记录
   */
  EDIT_CARBON_INSPECT = '/book/carbonInspect/editCarbonInspect',
  /**
   * 同步盘查数据
   */
  SYNC_INVENTORY_DATA = '/book/carbonInspect/syncInventoryData',
  /**
   * 配额预测
   */
  QUOTA_FORECAST_DATA = '/book/carbonInspect/quotaForecastData',
  /**
   * 获取该排放单位年剩余额度
   */
  FIND_CARBON_ALLOWANCE = '/book/carbonInspect/findCarbonAllowance',
  /**
   * 年度清缴履约
   */
  CARBON_EMISSION_INSPECT = '/book/carbonInspect/carbonEmissionPerformance',
  // 查询所有子组织列表
  GET_ORGANIZATION_CHILD_LIST = '/upms/organization/listChildByCode',
  // 删除核查任务
  DELETE_INSPET_TASK = '/book/carbonInspect/deleteInspectTask',
  // 获取核查任务详情
  GET_INSPET_INFO = '/book/carbonInspect/getInspectInfo',
  // 根据组织边界获取核查任务
  GET_CHILDREN_TREE = '/book/carbonInspect/getChildrenTree'
}

// 碳核查与履约分页列表
export const getInspectList = (
  params: GetInspectListParams & BasicPagingListParams
): Promise<BasicPagingListResult<GetInspectListResult>> => get(Api.GET_INSPECT_LIST, params)

/**
 * 新增工厂核查记录
 */
export const postCreateCarbonInspect = (params: PostCreateCarbonInspectParams): Promise<void> =>
  post(Api.CREATE_CARBON_INSPECT, params)

/**
 * 编辑碳核查记录
 */
export const postEditCarbonInspect = (params: PostEditCarbonInspectParams): Promise<void> =>
  post(Api.EDIT_CARBON_INSPECT, params)

/**
 * 同步盘查数据
 */
export const postSyncInventoryData = (
  params: Required<GetInspectListParams>
): Promise<PostSyncInventoryDataResult> => get(Api.SYNC_INVENTORY_DATA, params)

/**
 * 配额预测
 */
export const postQuotaForecastData = (
  params: PostQuotaForecastDataParams
): Promise<PostQuotaForecastDataResult> => post(Api.QUOTA_FORECAST_DATA, params)

/**
 * 获取该排放单位年剩余额度
 */
export const getFindCarbonAllowance = (
  params: Required<GetInspectListParams>
): Promise<GetFindCarbonAllowanceResult[]> => get(Api.FIND_CARBON_ALLOWANCE, params)

/**
 * 年度清缴履约
 */
export const postCarbonEmissionInspect = (params: PostCarbonEmissionInspectParams): Promise<void> =>
  post(Api.CARBON_EMISSION_INSPECT, params)

// 查询所有子组织列表
export const getChildByCodeList = (orgCode?: string): Promise<GetOrganizationListResult> =>
  get(Api.GET_ORGANIZATION_CHILD_LIST, { orgCode })

// 删除核查任务
export const deleteInspectTask = (inspectNo?: string): Promise<void> =>
  postByUrl(Api.DELETE_INSPET_TASK, { inspectNo })

// 获取核查任务详情
export const getInspectInfo = (inspectNo?: string): Promise<any> =>
  get(Api.GET_INSPET_INFO, { inspectNo })

// 根据组织边界获取核查任务
export const getChildrenTree = (inspectNo?: string): Promise<any> =>
  get(Api.GET_CHILDREN_TREE, { inspectNo })
